(* Copyright Per Lindgren 2015, see the file "LICENSE" *)
(* for the full license governing this code.           *)

(* FUN-4SURE/Id *)

let g_cnt = ref 0;;
let g_si = ref ([]:(string * int) list);;
let g_is = ref ([]:(int* string) list);;

let add (s:string) =
  try 
    List.assoc s !g_si                  (* return a corresponding int *)
  with
  | Not_found -> 
    let o_cnt = !g_cnt in               (* read counter impertively *)
    g_si := (s, o_cnt) :: !g_si;        (* update the storage *)
    g_is := (o_cnt, s) :: !g_is;        (* update the storage *)
     
    g_cnt := o_cnt + 1;                 (* update the counter*)
    o_cnt
    
let get_s (i:int) = List.assoc i !g_is 
let get_i (s:string) = List.assoc s !g_si 
   